﻿CREATE PROC vantage.s_NotesImport AS
SELECT [ID]
      ,[LoanID]
      ,[Note]
      ,[StatusID]
      ,[StatusDate]
      ,[StatusUser]
      ,[DateDue]
      ,[DateDueBy]
      ,[NoteTypeID]
      ,[NoteActionCodeID]
      ,[Phone]
      ,[PhoneCategoryID]
      ,[NoteDate]
      ,[IsTask]
      ,[NoteUser]
      ,[NoteDate0]
      ,[NoteDate1]
      ,[IsResolved]
      ,[IsCollection]
FROM [MotoBank].[dbo].[t_Note]

SELECT  T_N.Target_NoteID,
T_N.AccountNumber,
T_N.NoteSourceRef,
T_N.NoteTypeRef,
T_N.ActionTypeRef,
T_N.ResultTypeRef,
T_N.NoteImportanceRef,

                      T_N.NoteDate,
T_N.IsPublic,
T_N.Notes,
T_N.CreatedDate,
T_N.CreatedUser,
B.LoanID
FROM         Vantage.T_Note AS T_N INNER JOIN
                      vantage.t_Bridge_20 AS B ON T_N.AccountNumber = B.VantageID
WHERE NoteSourceRef IS NULL
ORDER BY CreatedDate DESC

SELECT     NoteSourceRef, COUNT(*) AS Expr1
FROM         Vantage.T_Note
GROUP BY NoteSourceRef

SELECT *

FROM         Vantage_In.dbo.Target_Note
WHERE NoteSourceRef IS NULL

SELECT     NoteTypeRef, COUNT(*) AS Expr1
FROM         Vantage.T_Note
GROUP BY NoteTypeRef

SELECT     ActionTypeRef, COUNT(*) AS Expr1
FROM         Vantage.T_Note
GROUP BY ActionTypeRef

SELECT     ResultTypeRef, COUNT(*) AS Expr1
FROM         Vantage.T_Note
GROUP BY ResultTypeRef
